<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue</title>
    <script src="../vue.js"></script>
    </style>
</head>

<body>
    <div id="root">
        firstname:<input type="text" v-model='firstname'><br> 昵称:
        <span>{{fullName2}}</span>
    </div>
    <script>
        Vue.config.productionTip = false
        const vm = new Vue({
            el: '#root',
            data: {
                firstname: 'chen',
                id: '3200541011'
            },
            computed: {//计算属性不能开启异步任务
                fullName: {
                    get() {
                        console.log('get被调用')
                        return this.firstname + this.id
                    },
                    // 计算属性有缓存特性，只在初次读取时和所依赖属性改变时刷新一次
                    set(value) {
                            this.firstname = value
                            console.log('set被调用')
                        }
                        // set用于设置属性，返回给data属性
                },
                // 不考虑修改时，有简写方法：
                fullName2() { // fullName2: function () {
                    console.log('get被调用')
                    return this.firstname + this.id
                        // 也就是直接把函数当作getter使用
                }
            },
            methods: {}
        })
    </script>
</body>

</html>